package cn.edu.hznu.notebook.service;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.hznu.notebook.dao.UserDao;
import cn.edu.hznu.notebook.entity.User;

@Service("UserService")
@Transactional(rollbackFor = {Exception.class})
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public User getUserById(Integer id) {
		return this.userDao.findById(id);
	}

	@Override
	public User signIn(String no) {
		return this.userDao.findByNo(no);
	}

	@Override
	public void signUp(User user) throws Exception {
		if (this.userDao.findByNo(user.getNo()) != null) {
			throw new Exception("this user no already exists.");
		}
		this.userDao.save(user);
	}

	@Override
	public void updateUserInfo(User user) throws Exception {
		this.userDao.update(user);
	}

	
}
